package com.itheima.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderSettingService;
import com.itheima.health.utils.poi.POIUtils;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**

 */
@RestController
public class OrderSettingController {

    @Reference
    private OrderSettingService orderSettingService;

    @PostMapping("ordersetting/importOrderSettings")
    public Result importOrderSettings(@RequestParam("excelFile") MultipartFile file) {
        List<String[]> orderSettingList = POIUtils.readExcel(file);
        orderSettingService.importOrderSettings(orderSettingList);
        return new Result(true);
    }

    @GetMapping("ordersetting/findSettingData/{year}/{month}")
    public Result findSettingDate(@PathVariable("year") int year, @PathVariable("month") int month) {
        return new Result(orderSettingService.findSettingData(year, month));
    }

    @PutMapping("ordersetting/updateNumberByOrderdate/{number}/{orderdate}")
    public Result updateNumberByOrderdate(@PathVariable("number") int number, @PathVariable("orderdate") String orderdate) {
        return new Result(orderSettingService.updateNumberByOrderdate(number, orderdate));
    }
}
